﻿using System.Data.Linq;

namespace DBHelper.DB
{
    public class PhoneData:System.Data.Linq.DataContext
    {
        public static string connectString = "Data Source=isostore:/PhoneData.sdf";

        public PhoneData(string dbconnstr)
            : base(dbconnstr)
        { }

        public Table<SettingTable> Setting;

        public Table<CustomSetTable> CustomSet;

        public static void CreateIfIsNotExists()
        {
            using (DBHelper.DB.PhoneData db = new DBHelper.DB.PhoneData(DBHelper.DB.PhoneData.connectString))
            {
                if (db.DatabaseExists() == false)
                {
                    //创建一个数据库
                    db.CreateDatabase();
                    DBHelper.DB.SettingTable st = new DBHelper.DB.SettingTable();
                    st.SettingName = "IpAddress";
                    st.SettingValue = "192.168.1.1";
                    db.Setting.InsertOnSubmit(st);
                    db.SubmitChanges();
                    st = new SettingTable();
                    st.SettingName = "Port";
                    st.SettingValue = "8096";
                    db.Setting.InsertOnSubmit(st);
                    db.SubmitChanges();
                }
            }
        }
    }
}
